package com.yydream.controller;

import com.yydream.common.utils.R;
import com.yydream.common.valid.AddGroup;
import com.yydream.common.valid.UpdateGroup;
import com.yydream.dto.SysCategoryDTO;
import com.yydream.dto.SysCategoryPageDTO;
import com.yydream.service.SysCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "分类管理功能接口")
@RestController
public class SysCategoryController {

    @Autowired
    private SysCategoryService sysCategoryService;


    @ApiOperation("通过Id查询单条数据")
    @GetMapping("/sysCategory/detail")
    public R queryById(@RequestParam(value = "id") Long id) {
        return sysCategoryService.queryById(id);
    }

    @ApiOperation("分页查询")
    @PostMapping("/sysCategory/list")
    public R pageList(@RequestBody SysCategoryPageDTO req) {
        return sysCategoryService.pageList(req);
    }

    @ApiOperation("根据名称批量新增数据")
    @PostMapping("/sysCategory/bashInsertByNames")
    public R bashInsertByNames(@RequestBody List<String> names) {
        return sysCategoryService.bashInsertByNames(names);
    }

    @ApiOperation("新增数据")
    @PostMapping("/sysCategory/insert")
    public R insert(@Validated(AddGroup.class) @RequestBody SysCategoryDTO req) {
        return sysCategoryService.insert(req);
    }

    @ApiOperation("更新数据")
    @PostMapping("/sysCategory/update")
    public R update(@Validated(UpdateGroup.class) @RequestBody SysCategoryDTO req) {
        return sysCategoryService.update(req);
    }

    @ApiOperation("通过主键删除数据")
    @PostMapping("/sysCategory/deleteById")
    public R deleteById(@RequestParam(value = "ids") Long[] ids) {
        return sysCategoryService.deleteById(ids);

    }

}
